// pages/subpackage/pages/crm/accounputForward/accounputForward.js
var app = getApp();
var WxParse = require('../../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    workInfo: [],
    is_auth:false,//是否实名
    redirect_url:'',//实名跳转页面
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.workerInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getRule();
    this.workerInfo();
    this.getAuthInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  // 提现
  withdrawal(e) {
    var that = this;
    //判断是否实名
    if(!that.data.is_auth){
      app.showToast("请先实名认证","none",3000,function(){
        wx.navigateTo({
          url: that.data. redirect_url,
        })
      });
    
      return false;
    }
    // var is_have_bank = that.data.workInfo.is_have_bank;
    // var workers_id = e.currentTarget.dataset.id;
    // console.log('is_have_bank', is_have_bank)
    wx.navigateTo({
      url: '../putForwardPrice/putForwardPrice'
    })
    // if (is_have_bank){
    //   wx.navigateTo({
    //     url: '../putForwardPrice/putForwardPrice'
    //   })
    // }else{
    //   wx.showModal({
    //     content: '请先绑定银行卡',
    //     showCancel: false,
    //     success(res) {
    //       if (res.confirm) {
    //         wx.navigateTo({
    //           url: '../addeditAccount/addeditAccount?type=2',
    //         })
    //       }
    //     }
    //   })
    // }
    
  },

  // 获取运营中心、合伙人信息
  workerInfo() {
    var that = this;
    app.ajax({
      url: "api/Withdraw/getAccountInfo",
      url_type: 2,
      data: {},
      success: function(res) {
        if (res.data.code == 1000) {
          that.setData({
            workInfo: res.data.data,
          })
        }
      }
    })
  },

  // 提现记录
  presentRecord(){
    var that = this;
    // var workers_id = that.data.workInfo.workers_id
    wx.navigateTo({
      url: '../presentRecord/presentRecord',
    })
  },
  //业绩记录
  achievementRecord() {
    var that = this;
    // var workers_id = that.data.workInfo.workers_id
    wx.navigateTo({
      url: '../achievementRecord/achievementRecord',
    })
  },
  
  // 提现账户设置
  presentAccount(){
    var that = this;
    // var workers_id = that.data.workInfo.workers_id
    wx.navigateTo({
      url: '../presentAccount/presentAccount',
    })
  },
  // 获取提现说明
  getRule() {
    var that = this;
    app.ajax({
      url: 'api/Article/getList',
      url_type: 2,
      data: {
        cate_sn: 'AVwsyFwB'
      },
      success: function (res) {
        if (res.data.code == 1000) {
          var article = res.data.data[0].content;
          WxParse.wxParse('article', 'html', article, that, 5);
        }
      }
    })
  },
   //获取用户认证信息
   getAuthInfo() {
    var that = this;
    var url = "api/Realname/getAuthInfo";
    var data =  {auth_role:2};
    var url_type = 2;
    app.ajax({
      url: url,
      url_type:url_type,
      data: data,
      success: function (res) {
        if (res.data.code == 1000 && res.data.data.status==2) {
        that.setData({
          is_auth: true
        })
      }
      var redirect_url = '';
        if (res.data.code == 1000 && (res.data.data.status == -2 || res.data.data.status == -4)) {
             redirect_url = '/pages/realname/uploadDocuments/uploadDocuments?auth_role=2';
        } else if (res.data.code == 1000 && res.data.data.status == -3) {
            redirect_url = '/pages/realname/faceRecognition/faceRecognition?auth_role=2';
        } else if (res.data.code == 1000 &&  res.data.data.status == 1) {
            redirect_url = '/pages/realname/myCertification/myCertification?auth_role=2';
        } else if(res.data.code==-1003) {
            redirect_url ='/pages/realname/realName/realName?auth_role=2';
       }
      that.setData({
          redirect_url: redirect_url
      })
    }
    })
  },
  
})